package cn.schoolwow.workflow.module.task.action.flow.complete.transaction;

import cn.schoolwow.quickdao.domain.transaction.Transaction;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.domain.task.CompleteTaskRequest;
import cn.schoolwow.workflow.entity.WorkFlowInstance;
import cn.schoolwow.workflow.entity.WorkFlowTask;

public class UpdateWorkFlowInstanceTaskFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        Transaction transaction = flowContext.checkInstanceData(Transaction.class);
        WorkFlowInstance workFlowInstance = flowContext.checkInstanceData(WorkFlowInstance.class);
        CompleteTaskRequest completeTaskRequest = flowContext.checkInstanceData(CompleteTaskRequest.class);

        transaction.addRecordString("更新工作流任务为完成状态");
        transaction.query(WorkFlowTask.class)
                .addQuery("id", completeTaskRequest.taskId)
                .addQuery("instanceId", workFlowInstance.getId())
                .addUpdate("complete", true)
                .execute()
                .update();
        transaction.commit();
    }

    @Override
    public String name() {
        return "完成流程任务-更新工作流实例任务";
    }

}
